<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layui</title>
    <link rel="stylesheet" href="./layui/css/layui.css"> </head>
<script src="./layui/layui.js"></script>

<body>
    <script>
        /*
          Demo1.js
          使用Layui的form和upload模块
        */
        //如果只加载一个模块，可以不填数组。如：layui.use('form')
        layui.use(['form', 'upload'], function () {
            var form = layui.form //获取form模块
                , upload = layui.upload; //获取upload模块
            //监听提交按钮
            form.on('submit(test)', function (data) {
                console.log(data);
            });
            //实例化一个上传控件
            upload({
                url: '上传接口url'
                , success: function (data) {
                    console.log(data);
                }
            })
        });

        //下面是在一个事件回调里去加载一个Layui模块
        button.addEventListener('click', function () {
            //多次调用use并不会重复加载laytpl.js，Layui内部有做模块cache处理。
            layui.use('laytpl', function (laytpl) {
                var html = laytpl('').render({});
                console.log(html);
            });
        });

        //强烈不推荐下面的做法
        var laypage, laydate;
        layui.use(['laypage', 'laydate'], function () {
            laypage = layui.laypage;
            laydate = layui.laydate;
        });
    </script> </body>

</html>